//
// Created by guo on 24-8-30.
//

#ifndef BBDEMO_BBCLIENT_H
#define BBDEMO_BBCLIENT_H

#include "TCPClient.hpp"
#include "Blackboard.h"
#include "protocol.h"
#include <thread>
#include <atomic>

class BBClient {
public:
    ~BBClient();
    bool connect(const std::string& ip, uint16_t port);
    void run();
    void set_blackboard(const std::string& key, const std::string& value);
    bool get_blackboard(const std::string& key, std::string& value);
    void erase_blackboard(const std::string& key);
protected:
    void handle_data();
    void parse_data(const std::string &data, std::vector<std::pair<BBMsg, std::string>> &vec_msg);
    void handle_msg(std::vector<std::pair<BBMsg, std::string>>& vec_msg);
private:
    TCPClient* _client;
    std::thread _t;
    std::atomic<bool> _exit;

    void poll_one();
};


#endif //BBDEMO_BBCLIENT_H
